package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.role.RoleDTO;
import com.qk.entity.Role;
import com.qk.management.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Just、倾城
 * @created 2025-10-09
 * @description
 *
 */
@Slf4j
@RestController
@RequestMapping("/roles")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PutMapping
    public Result update(@RequestBody Role role){
        roleService.update(role);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询角色");
        Role role = roleService.getById(id);
        return Result.success(role);
    }
    /**
     * 添加角色
     * @param role
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Role role){
        roleService.add(role);
        return Result.success();
    }
    /**
     * 删除角色
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除角色");
        roleService.deleteById(id);
        return Result.success();
    }
    /**
     * 角色列表查询
     * @return
     */
    @GetMapping
    public Result roleList(RoleDTO roleDTO) {
        log.info("角色列表查询");
        PageResult<Role> data = roleService.roleList(roleDTO);
        return Result.success(data);
    }


    /**
     * 查询所有角色
     * @return
     */
    @GetMapping("/list")
    public Result list() {
        log.info("查询所有角色");
        List<Role> list = roleService.list();
        return Result.success(list);
    }
}
